﻿//  --------------------------------
//  Copyright (c) PK Logix LLC. All rights reserved.
//  This source code is made available under the terms of the GNU General Public License version 2 (GPLv2)
//  http://www.codeplex.com/mvcclubsite/license
//  ---------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MVCClubSite.IDAL;
using MVCClubSite.Model;

namespace MVCClubSite.BLL
{
    /// <summary>
    /// This is the business component to manage locations
    /// </summary>
    public class LocationsService
    {
        ILocations _locations;

        /// <summary>
        /// Default constructor that will use the DAL set in the web config
        /// </summary>
        public LocationsService()
        {
            _locations = MVCClubSite.DALFactory.DataAccess.CreateLocations();
        }

        /// <summary>
        /// Constructor for testing with a different DAL
        /// </summary>
        /// <param name="announcements">DAL for the announcement service to use</param>
        public LocationsService(ILocations locations)
        {
            _locations = locations;
            if (_locations == null)
                throw new InvalidOperationException("Locations DAL cannot be null.");
        }

        /// <summary>
        /// Method to get locations
        /// </summary>
        /// <returns></returns>
        public List<Location> GetLocations()
        {
            return (from l in _locations.GetLocations()
                    orderby l.Title ascending
                    select l).ToList();
        }

        /// <summary>
        /// Method to get a location by ID
        /// </summary>
        /// <param name="id">ID of the location</param>
        /// <returns>Location business entity</returns>
        public Location GetLocationByID(int id)
        {
            return _locations.GetLocationByID(id);
        }

        /// <summary>
        /// Method to insert or update a location
        /// </summary>
        /// <param name="location">Location to insert or update</param>
        public void Save(Location location)
        {
            _locations.Save(location);
        }

        /// <summary>
        /// Method to delete a location
        /// </summary>
        /// <param name="id">ID of the location</param>
        public void Delete(int id)
        {
            _locations.Delete(id);
        }
    }
}
